home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / progem.lzh / wind9.prf < prev   
Encoding:
Text File  |  1987-06-23  |  20.7 KB  |  482 lines

  1. .!****************************************************************************
  2. .! 
  3. .! ANTIC PUBLISHING INC., COPYRIGHT 1985.  REPRINTED BY PERMISSION.
  4. .!
  5. .! ** Professional GEM ** by Tim Oren
  6. .!
  7. .! Proff File by ST enthusiasts at
  8. .! Case Western Reserve University
  9. .! Cleveland, Ohio
  10. .! uucp : decvax!cwruecmp!bammi
  11. .! csnet: bammi@case
  12. .! arpa : bammi%case@csnet-relay
  13. .! compuserve: 71515,155
  14. .!
  15. .!****************************************************************************
  16. .!
  17. .!
  18. .!****************************************************************************
  19. .!
  20. .!            Begin Part 9
  21. .!
  22. .!****************************************************************************
  23. .!
  24. .PART IX VDI Graphics: Lines and Solids
  25. .PP
  26. This  issue  of ST PRO GEM is the first in a  series  of  two
  27. which  will explore the fundamentals of VDI graphics  output.   In
  28. this installment, we will take a look at the commands necessary to
  29. output simple graphics such as lines,  squares and circles as well
  30. as  more complex figures such as polygons.   The following episode
  31. will  take a first look at graphics text output,  with an emphasis
  32. on  ways  to  optimize its drawing speed.   It will  also  include
  33. another  installment  of ONLINE Feedback.   As usual,  there is  a
  34. download  with  this column.   You should find it under  the  name
  35. GEMCL9.C in DL3 of ATARI16 (PCS-58).
  36. .SH A  BIT  OF HISTORY
  37. One  of  the reasons that the VDI can  be  confusing  is  that
  38. drawing anything at all,  even a simple line,  can involve setting
  39. around four different VDI parameters before making the draw  call!
  40. (Given  the state of the GEM documents,  just FINDING them can  be
  41. fun!)  Looking backwards a bit sheds some light on why the VDI  is
  42. structured this way,  and also gives us a framework for organizing
  43. a discussion of graphics output.
  44. .PP
  45. The GEM VDI closely follows the so-called GKS standard, which
  46. defines  capabilities  and calling sequences  for  a  standardized
  47. graphic  input/output system.   GKS is itself an evolution from an
  48. early system called "Core".   Both of these standards were born in
  49. the  days  when  pen plotters,  vectored  graphics  displays,  and
  50. minicomputers  were  the  latest items.   So,  if you  wonder  why
  51. setting  the drawing pen color is a separate command,  just  think
  52. back  a  few  years when it actually meant  what  it  says!   (The
  53. cynical   may   choose   instead  to  ponder   the   benefits   of
  54. standardization.)
  55. .PP
  56. When  doing  VDI  output,  it helps if you pretend  that  the
  57. display screen really is a plotter or some other separate  device,
  58. which  has  its own internal parameters which you can set  up  and
  59. read  back.   The class of VDI commands called Attribute Functions
  60. let  you set the parameters.   Output Functions cause the "device"
  61. to  actually  draw  someone once it is  configured.   The  Inquire
  62. Functions let you read back the parameters if necessary.
  63. .PP
  64. There  are two parameters which are relevant no  matter  what
  65. type of object you are trying to draw.   They are the writing mode
  66. and  the clipping rectangle.   The writing mode is similar to that
  67. discussed in the column on raster operations.   It determines what
  68. effect the figure you are drawing will have on data already on the
  69. screen.  The writing mode is set with the call:
  70. .FB vswr_mode()
  71. vswr_mode(vdi_handle, mode);
  72. .FE
  73. Vdi_handle,  here  and  below,  is the  handle  obtained  from
  74. graf_handle at the beginning of the program.  Mode is a word which
  75. may be one of:
  76. .sp 1
  77. .in +8
  78. 1 - Replace Mode
  79. .br
  80. 2 - Transparent Mode
  81. .br
  82. 3 - XOR mode
  83. .br
  84. 4 - Reverse Transparent Mode
  85. .in -8
  86. .PP
  87. In  replace mode,  whatever is on the screen is  overwritten.
  88. If  you are writing characters,  this means the background of each
  89. character cell will be erased.
  90. .PP
  91. In  transparent  mode,  only  the pixels directly  under  the
  92. "positive"  part  of the image,  that is,  where 1-bits are  being
  93. written, will be changed.  When writing characters, the background
  94. of the cell will be left intact.
  95. .PP
  96. In XOR mode,  an exclusive or is performed between the screen
  97. contents and what is being written.   The effect is to reverse the
  98. image under areas where a 1-bit occurs.
  99. .PP
  100. Reverse transparent is like transparent,  but with a "reverse
  101. color  scheme".   That  is,  only  places where a 0-bit is  to  be
  102. put   are  changed  to  the  current  writing  color.    When  you
  103. write  characters in reverse transparent (over white),  the effect
  104. is reverse video.
  105. .PP
  106. The  other  common parameter is the clipping  rectangle.   It
  107. defines the area on the screen where the VDI is permitted to draw.
  108. Any output which would fall outside of this area is ignored; it is
  109. effectively a null operation.   The clip rectangle is set with the
  110. call:
  111. .FB vs_clip()
  112. vs_clip(vdi_handle, flag, pxy);
  113. .FE
  114. Pxy is a four-word array.   Pxy[0] and pxy[1] are the X  and  Y
  115. screen coordinates,  respectively,  of one corner of your clipping
  116. rectangle.    Pxy[2]  and  pxy[3]  are  the  coordinates  of   the
  117. diagonally opposite corner of the rectangle.   (When working  with
  118. the  AES,  use  of  a  GRECT to define  the  clip  is  often  more
  119. convenient.  The routine set_clip() in the download does this.)
  120. .PP
  121. Flag is set to TRUE if clipping is to be used.  If you set it
  122. to  FALSE,  the  entire  screen is assumed to be fair  game.
  123. .PP
  124. Normally,  you should walk the rectangle list for the current
  125. window to obtain your clipping rectangles.  (See ST PRO GEM #2 for
  126. more details.)  However, turning off the clip speeds up all output
  127. operations,  particularly text.  You may do this ONLY when you are
  128. absolutely certain that the figure you are drawing will not extend
  129. out of the top-most window, or out of a dialog.
  130. .SH THE LINE FORMS ON THE LEFT
  131. The  VDI  line  drawing  operations  include  polyline,  arc,
  132. elliptical  arc,  and rounded rectangle.   I'll first look at  the
  133. Attribute Functions for line drawing,  then go through the drawing
  134. primitives themselves.
  135. .PP
  136. The  most  common used line attributes are color  and  width.
  137. The color is set with:
  138. .FB vsl_color()
  139. vsl_color(vdi_handle, color);
  140. .FE
  141. where color is one of the standard VDI color  indices,  ranging
  142. from  zero to 15.   (As discussed in column #6,  the  color  which
  143. actually appears will depend on the pallette setting of your ST.)
  144. .PP
  145. The  line width may only be set to ODD positive  values,  for
  146. reasons  of  symmetry.   If you try to set an even value,  the VDI
  147. will take the next lower odd value.  The call is:
  148. .FB vsl_width()
  149. vsl_width(vdi_handle, width);
  150. .FE
  151. The  two  less  used line parameters are the  end  style  and
  152. pattern.   With  the  end style you can cause the output  line  to
  153. have rounded ends or arrowhead ends.  The call is:
  154. .FB vsl_ends()
  155. vsl_ends(vdi_handle, begin_style, end_style);
  156. .FE
  157. Begin_style  and end_style are each words which  may  have  the
  158. values zero for square ends (the default),  one for arrowed  ends,
  159. or  two  for  rounded ends.   They determine the  styles  for  the
  160. starting and finishing ends of the line, respectively.
  161. .PP
  162. The line pattern attribute can select dotted or dashed  lines
  163. as  well  as more complicated patterns.   Before  continuing,  you
  164. should  note one warning:  VDI line output DOES NOT compensate for
  165. pixel aspect ratio.  That is, the dashes on a line will look twice
  166. as long drawn vertically on a medium-res ST screen as they do when
  167. drawn horizontally.  The command for setting the pattern is:
  168. .FB vsl_type()
  169. vsl_type(vdi_handle, style);
  170. .FE
  171. Style  is  a word with a value between 1  and  7.   The  styles
  172. selected are:
  173. .sp 1
  174. .in +8
  175. 1 - Solid (the default)
  176. .br
  177. 2 - Long Dash
  178. .br
  179. 3 - Dot
  180. .br
  181. 4 - Dash, Dot
  182. .br
  183. 5 - Dash
  184. .br
  185. 6 - Dash, Dot, Dot
  186. .br
  187. 7 - (User defined style)
  188. .in -8
  189. .PP
  190. The  user  defined  style is determined  by  a  16-bit  pattern
  191. supplied  by the application.   A one bit in the pattern  turns  a
  192. pixel on, a zero bit leaves it off.  The pattern is cycled through
  193. repeatedly,  using the high bit first.  To use a custom style, you
  194. must make the call:
  195. .FB vsl_udsty()
  196. vsl_udsty(vdi_handle, pattern);
  197. .FE
  198. before doing vsl_type().
  199. .PP
  200. As  I  mentioned  above,   the  line  type  Output  Functions
  201. available are polyline,  circular and ellliptical arc, and rounded
  202. rectangle.   Each  has  its own calling sequence.   The call for a
  203. polyline is:
  204. .FB v_pline()
  205. v_pline(vdi_handle, points, pxy);
  206. .FE
  207. Points tells how many vertices will appear on the polyline.  For
  208. instance,  a  straight  line has two vertices:  the  end  and  the
  209. beginning.   A closed square would have five,  with the first  and
  210. last  identical.    (There  is  no  requirement  that  the  figure
  211. described be closed.)
  212. .PP
  213. The pxy array contains the X and Y raster coordinates for the
  214. vertices,  with a total of 2 * points entries.   Pxy[0] and pxy[1]
  215. are the first X-Y pair, and so on.
  216. .PP
  217. If you happen to be using the XOR drawing mode, remember that
  218. drawing  twice  at  a point is equivalent to no  drawing  at  all.
  219. Therefore,  for  a figure to appear closed in XOR mode,  the final
  220. stroke  should actually stop one pixel short of the origin of  the
  221. figure.
  222. .PP
  223. You  may  notice  that  in the GEM  VDI  manual  the  rounded
  224. rectangle  and arc commands are referred to as  GDPs  (Generalized
  225. Drawing Primitives).  This denotation is historical in nature, and
  226. has  no effect unless you are writing your own VDI bindings.
  227. .PP
  228. The  rounded rectangle is nice to use for customized  buttons
  229. in  windows and dialogs.   It gives a "softer" look to the  screen
  230. than the standard square objects.  The drawing command is:
  231. .FB v_rbox()
  232. v_rbox(vdi_handle, pxy);
  233. .FE
  234. Pxy  is  a  four word array  giving  opposite  corners  of  the
  235. rectangle,  just as for the vs_clip() call.   The corner  rounding
  236. occurs  within  the  confines of  this  rectangle.   Nothing  will
  237. protrude  unless  you specify a line thickness greater  than  one.
  238. The  corner rounding is approximately circular;  there is no  user
  239. control over the degree or shape of rounding.
  240. .PP
  241. Both the arc and elliptical arc commands use a curious method
  242. of  specifying  angles.   The units are tenths of degrees,  so  an
  243. entire  circle is 3600 units.   The count starts at ninety degrees
  244. right of vertical, and proceeds counterclockwise.  This means that
  245. "3 o'clock" is 0 units,  "noon" is 900 units,  "9 o'clock" is 1800
  246. units, and 2700 units is at "half-past".  3600 units take you back
  247. to "3 o'clock".
  248. .PP
  249. The command for drawing a circular arc is:
  250. .FB v_arc()
  251. v_arc(vdi_handle, x, y, radius, begin, end);
  252. .FE
  253. X  and y specify the raster coordinates of the  center  of  the
  254. circle.   Radius specifies the distance from center to all  points
  255. on the arc.   Begin and end are angles given in units as described
  256. above,  both with values between 0 and 3600.   The drawing of  the
  257. arc  ALWAYS  proceeds  counterclockwise,   in  the  direction   of
  258. increasing arc number.   So values of 0 and 900 for begin and  end
  259. would  draw  a  quarter circle from  "three  o'clock"  to  "noon".
  260. Reversing  the values would draw the other three quarters  of  the
  261. circle.
  262. .PP
  263. A  v_arc()  command  which specifies a  "full  turn"  is  the
  264. fastest  way to draw a complete circle on the screen.   Be warned,
  265. however,  that  the circle drawing algorithm used in the VDI seems
  266. to  have  some  serious  shortcomings at  small  radii!   You  can
  267. experiment  with  the  CIRCLE primitive in  ST  Logo,  which  uses
  268. v_arc(), to see what I mean.
  269. .PP
  270. Notice  that if you want an arc to strike one or more  given
  271. points on the screen,  then you are in for some trigonometry.   If
  272. your  math  is  a  bit  rusty,  I highly  recommend  the  book  "A
  273. Programmer's  Geometry",  by  Bowyer  and Woodwark,  published  by
  274. Butterworths (London, Boston, Toronto).
  275. .PP
  276. Finally, the elliptical arc is generated with:
  277. .FB v_ellarc()
  278. v_ellarc(vdi_handle, x, y, xrad, yrad, begin, end);
  279. .FE
  280. X,  y,  begin, and end are just as before.  Xrad and yrad give the
  281. horizontal and vertical radii of the defining ellipse.  This means
  282. that  the distance of the arc from center will be yrad  pixels  at
  283. "noon"  and  "half-past",  and it will be xrad pixels at "3 and  9
  284. o'clock".  Again, the arc is always drawn counterclockwise.
  285. .PP
  286. There  are  a  number  of approaches  to  keeping  the  VDI's
  287. attributes "in sync" with the actual output operations.   Probably
  288. the  LEAST efficient is to use the Inquire Functions to  determine
  289. the  current  attributes.   For  this  reason,  I have  omitted  a
  290. discussion of these calls from this column.
  291. .PP
  292. Another  idea  is  to keep a local copy  of  all  significant
  293. attributes, use a test-before-set method to minimize the number of
  294. Attribute  Functions which need to be called.   This puts a burden
  295. on  the programmer to be sure that the local  attribute  variables
  296. are correctly maintained.   Failure to do so may result in obscure
  297. drawing  bugs.   If  your  application employs  user  defined  AES
  298. objects, you must be very careful because GEM might call your draw
  299. code  in the middle of a VDI operation (particularly if  the  user
  300. defined objects are in the menu).
  301. .PP
  302. Always  setting  the attributes is a simplistic  method,  but
  303. often   proves  most  effective.    The  routines  pl_perim()  and
  304. rr_perim()  in the download exhibit this  approach.   Modification
  305. for  other  primitives  is straightforward.   This style  is  most
  306. useful  when  drawing  operations  are  scattered  throughout  the
  307. program,  so that keeping track of the current attribute status is
  308. difficult.  Although inherently inefficient, the difference is not
  309. very  noticable if the drawing operation requested is itself  time
  310. consuming.
  311. .PP
  312. In  many  applications,  such  as data graphing  programs  or
  313. "Draw"  packages,  the output operations are centralized,  forming
  314. the primary functionality of the code.   In this case,  it is both
  315. easy  and  efficient  to keep track of  attribute  status  between
  316. successive drawing operations.
  317. .SH SOLIDS
  318. There  are  a wider variety of VDI  calls  for  drawing  solid
  319. figures.   They  include rectangle or  bar,  disk,  pie,  ellipse,
  320. elliptical  pie,  filled rounded rectangle,  and filled  polygonal
  321. area.   Of course,  filled figure calls also have their own set of
  322. attributes which you will need to set.
  323. .PP
  324. The  fill color index determines what pen color will be  used
  325. to draw the solid.  It is set with:
  326. .FB vsf_color()
  327. vsf_color(vdi_handle, color);
  328. .FE
  329. Color is just the same as for line drawing.   A solid may  or
  330. may not have a visible border.  This is determined with the call:
  331. .FB vsf_perimeter()
  332. vsf_perimeter(vdi_handle, vis);
  333. .FE
  334. Vis is a Boolean.   If it is true,  the figure will be given  a
  335. solid one pixel outline in the current fill color index.   This is
  336. often  useful  to improve the appearance of solids  drawn  with  a
  337. dithered fill pattern.  If vis is false, then no outline is drawn.
  338. .PP
  339. There are two parameters which together determine the pattern
  340. used  to  fill your figure.   They are called interior  style  and
  341. interior  index.   The style determines the general type of  fill,
  342. and the index is used to select a particular pattern if necessary.
  343. The style is set with the command:
  344. .FB vsf_interior()
  345. vsf_interior(vdi_handle, style);
  346. .FE
  347. where style is a value from zero through four.   Zero selects  a
  348. hollow  style:  the  fill is performed in  color  zero,  which  is
  349. usually  white.   Style one selects a solid fill with the  current
  350. fill  color.   A style of two is called "pattern" and a  three  is
  351. called "hatch", which are terms somewhat suggestive of the options
  352. which can then be selected using the interior index.   Style  four
  353. selects the user defined pattern, which is described below.
  354. .PP
  355. The  interior  index is only significant for styles  two  and
  356. three. To set it, use:
  357. .FB vsf_style()
  358. vsf_style(vdi_handle, index);
  359. .FE
  360. (Be careful here: it is very easy to confuse this call with the
  361. one  above  due  to the unfortunate choice of  name.)   The  index
  362. selects the actual drawing pattern.  The GEM VDI manual shows fill
  363. patterns corresponding to index values from 1 to 24 under style 2,
  364. and  from  1 to 12 under style 3.   However,  some  of  these  are
  365. implemented  differently on the ST.   Rather than try to  describe
  366. them all here, I would suggest that you experiment.  You can do so
  367. easily  in  ST Logo by opening the Graphics  Settings  dialog  and
  368. playing with the style and index values there.
  369. .PP
  370. The user defined style gives you some interesting options for
  371. multi-color fills.  It is set with:
  372. .FB vsf_udpat()
  373. vsf_udpat(vdi_handle, pattern, planes);
  374. .FE
  375. Planes  determines the number of color planes in  the  pattern
  376. which  you  supply.   It  is  set to one  if  you  are  setting  a
  377. monochrome  pattern.   (Remember,  monochrome is  not  necessarily
  378. black).   It may be set to higher values on color systems: two for
  379. ST medium-res mode, or four for low-res mode.  If you use a number
  380. lower than four under low-res, the other planes are zero filled.
  381. .PP
  382. The  pattern  parameter  is  an array of  words  which  is  a
  383. multiple  of  16 words long.  The pattern determined is 16  by  16
  384. pixels,  with each word forming one row of the pattern.   The rows
  385. are  arranged top to bottom,  with the most significant bit to the
  386. left.   If  you  have selected a multi-plane pattern,  the  entire
  387. first plane is stored, then the second, and so on.
  388. .PP
  389. Note that to use a multi-plane pattern, you set the writing
  390. mode  to replace using vswr_mode().   Since the each plane can  be
  391. different,  you can produce multi-colored patterns.   If you use a
  392. writing   color  other  than  black,   some  of  the  planes   may
  393. "disappear".
  394. .PP
  395. Most  of  the  solids Output Functions  have  analogous  line
  396. drawing commands.   The polyline command corresponds to the filled
  397. area primitive.  The filled area routine is:
  398. .FB v_fillarea()
  399. v_fillarea(vdi_handle, count, pxy);
  400. .FE
  401. Count  and pxy are just the same as  for  v_pline().   If  the
  402. polygon  defined  by pxy is not closed,  then the VDI  will  force
  403. closure  with  a straight line from the last to the  first  point.
  404. The  polygon may  be concave or self-intersecting.   If  perimeter
  405. show is on, the area will be outlined.
  406. .PP
  407. One  note of caution is necessary for both  v_fillarea()  and
  408. v_pline().   There is a limit on the number of points which may be
  409. stored in pxy[].   This limit occurs because the contents of pxy[]
  410. are copied to the intin[] binding array before the VDI is  called.
  411. You  can  determine  the maximum number of  vertices  by  checking
  412. intout[14] after using the extended inquire function vq_extnd().
  413. .PP
  414. For  reasons unknown to this writer,  there are TWO different
  415. filled rectangle commands in the VDI.  The first is
  416. .FB vr_recfl()
  417. vr_recfl(vdi_handle, pxy);
  418. .FE
  419. Pxy is a four word array defining two opposite corners of  the
  420. rectangle,  just  as  in  vs_clip().   Vr_recfl()  uses  the  fill
  421. attribute settings, except that it NEVER draws a perimeter.
  422. .PP
  423. The other rectangle routine is v_bar(), with exactly the same
  424. arguments  as  vr_recfl().    The  only  difference  is  that  the
  425. perimeter  setting  IS  respected.   These two  routines  are  the
  426. fastest way to produce a solid rectangle using the VDI.   They may
  427. be  used in XOR mode with a BLACK fill color to quickly invert  an
  428. area  of  the screen.   You can improve the speed even further  by
  429. turning off the clip (if possible), and byte aligning the left and
  430. right edges of the rectangle.
  431. .PP
  432. Separate commands are provided for solid circle and  ellipse.
  433. The circle call is:
  434. .FB v_circle()
  435. v_circle(vdi_handle, x, y, radius);
  436. .FE
  437. and the ellipse command is:
  438. .FB v_ellipse()
  439. v_ellipse(vdi_handle, x, y, xrad, yrad);
  440. .FE
  441. All of the parameters are identical to those given  above  for
  442. v_arc()  and v_ellarc().   The solid analogue of an arc is a  "pie
  443. slice".  The VDI pie commands are:
  444. .FB v_pieslice()
  445. v_pieslice(vdi_handle, x, y, radius, begin, end);
  446. .FE
  447. for a slice from a circular pie, and
  448. .FB v_ellpie()
  449. v_ellpie(vdi_handle, x, y, xrad, yrad, begin, end);
  450. .FE
  451. for a slice from a "squashed" pie.   Again,  the parameters are
  452. identical  to  those in v_arc() and  v_ellarc().   The  units  and
  453. drawing  order  of angles are also the  same.   The  final  solids
  454. Output Function is:
  455. .FB v_rfbox()
  456. v_rfbox(vdi_handle, pxy);
  457. .FE
  458. which draws a filled rounded rectangle.   The pxy array  defines
  459. two  two  opposite  corners of the  bounding  box,  as  shown  for
  460. vs_clip().
  461. .PP
  462. The  issues involved in correctly setting the VDI  attributes
  463. for a fill operation are identical to those in drawing lines.  For
  464. those  who  want to employ the "always set" method,  I have  again
  465. included  two  skeleton  routines in the download,  which  can  be
  466. modified as desired.
  467. .SH TO  BE  CONTINUED
  468. This concludes the first part of our expedition  through  basic
  469. VDI  operations.   The  next  issue will tackle  the  problems  of
  470. drawing  bit mapped text at a reasonable speed.   This first  pass
  471. will  not attempt to tackle alternate or  proportional  fonts,  or
  472. alternate font sizes.   Instead,  I will concentrate on techniques
  473. for  squeezing greater performance out of the standard  monospaced
  474. system fonts.
  475. .!
  476. .!
  477. .!*****************************************************************************
  478. .!*                                          *
  479. .!*                End Part 9                      *
  480. .!*                                          *
  481. .!*****************************************************************************
  482.